package com.itheima.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.tanhua.api.BlackListApi;
import com.itheima.tanhua.domain.BlackList;
import com.itheima.tanhua.domain.UserInfo;
import com.itheima.tanhua.dubbo.mappers.BlackListMapper;
import com.itheima.tanhua.dubbo.mappers.UserInfoMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void removeBlack(Long uid, Long blackUserId) {
        LambdaQueryWrapper<BlackList> qw = Wrappers.lambdaQuery(BlackList.class);
        qw.eq(BlackList::getUserId, uid)
                .eq(BlackList::getBlackUserId, blackUserId);
        blackListMapper.delete(qw);
    }

    @Override
    public IPage<UserInfo> findByUserIdToPage(Long id, Integer page, Integer pageSize) {
        Page<UserInfo> pages = new Page<>(page, pageSize);
        userInfoMapper.findPageByUserIds(pages, id);
        return pages;
    }
}